﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.GData.Spreadsheets;

namespace GoogleFeeder
{
    public class Spreadsheet
    {
        public readonly Spreadsheets Parent;
        public readonly SpreadsheetEntry Sheet;

        public Spreadsheet(Spreadsheets parent, SpreadsheetEntry sheet)
        {
            Parent = parent;
            Sheet = sheet;
        }

        public List<WorksheetEntry> Worksheets
        {
            get
            {
                WorksheetFeed wsFeed = Sheet.Worksheets;
                return wsFeed.Entries.ToList().Cast<WorksheetEntry>().ToList();
            }
        }

        public Worksheet GetSheetByIndex(int index)
        {
            var worksheets = Worksheets;
            if (worksheets.Count < index + 1)
                throw new Exception("Worksheet indexed " + index + " not found, there are only " + worksheets.Count + " of them there");
            return new Worksheet(this, worksheets[index]); 
        }
    }
}
